﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using DevExpress.Web;
using System.Collections.Generic;
using 聚欣订单分析.PublicClass;

namespace 聚欣订单分析
{
    public partial class eqMoney : System.Web.UI.Page
    {
        int id = 0;
        int parentID = 0;
        PLSQLClass plsql = new PLSQLClass();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ASPxTreeList1.DataBind();

                ASPxTreeList1.ExpandToLevel(1);

            }
            //ASPxTreeList1.ExpandToLevel(0);
        }

        protected void ASPxAdd_Click(object sender, EventArgs e)
        {
            this.grid.AddNewRow();
            //parentID = (int)ASPxTreeList1.FocusedNode["ParentID"];
            //id = (int)ASPxTreeList1.FocusedNode["ID"];
            //if (parentID > 0)
            //{
            //    this.grid.AddNewRow();
            //}
            //else
            //{
            //    JsHelper.Alert("请选择类型！");
            //}

            //this.grid.AddNewRow();
        }

        protected void grid_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
        {


            string strProName = "";
            string strProMoney = "";
            string strProRemarks = "";
            string strZk = "";
            if (e.NewValues["ProName"] == null)
            {
                e.RowError = "名称不能为空！";
                return;
            }
            else
            {
                strProName = e.NewValues["ProName"].ToString();
            }
            if (e.NewValues["ProMoney"] == null)
            {
                e.RowError = "价格不能为空！";
                return;
            }
            else
            {
                strProMoney = e.NewValues["ProMoney"].ToString();
            }
            if (e.NewValues["zk"] == null)
            {
                e.RowError = "折扣不能为空！";
                return;
            }
            else
            {
                strZk = e.NewValues["zk"].ToString();
            }
            if (e.NewValues["ProRemarks"] != null)
            {
                strProRemarks = e.NewValues["ProRemarks"].ToString();
            }
            //新建
            if (e.IsNewRow)
            {
                parentID = (int)ASPxTreeList1.FocusedNode["ParentID"];
                id = (int)ASPxTreeList1.FocusedNode["ID"];
                if (parentID == 0)
                {
                    e.RowError = "请选择类型！";
                    return;
                }
                plsql.SqlGetData("insert into tbl_product VALUES(" + id.ToString() + "," + parentID.ToString() + ",'" + strProName + "','" + strProMoney + "','" + strZk + "','" + strProRemarks + "')");
            }
            else//编辑
            {
                plsql.SqlGetData("update tbl_product set ProName='" + strProName + "',ProMoney='" + strProMoney + "',ProRemarks='" + strProRemarks + "',zk=" + strZk + " where ID=" + e.Keys[0].ToString());
            }
            grid.CancelEdit();
            grid.DataBind();
        }

        //protected void ASPxTreeList1_BeforeGetCallbackResult(object sender, EventArgs e)
        //{
        //    if (ASPxTreeList1.FocusedNode != null)
        //    {
        //        //sid = (int)ASPxTreeList1.FocusedNode["BranchNo"];
        //      //  id = (int)ASPxTreeList1.FocusedNode["ID"];
        //        //parentID = (int)ASPxTreeList1.FocusedNode["ParentID"];
        //    }

        //}
    }
}
